#/bin/bash
#1、通过软连接使项目能够访问指定的grpc proto file
mkdir -p ./pb/shared ./pb/util ./pb/service ./src/grpc-client/
rm ./pb/shared/message.proto
rm ./pb/util/status.proto
rm ./pb/service/*.proto
ln -s $GOPATH/bgs/grpc/pb/shared/message.proto ./pb/shared/message.proto
ln -s $GOPATH/bgs/grpc/pb/util/status.proto ./pb/util/status.proto
ln -s $GOPATH/bgs/grpc/pb/service/user.proto ./pb/service/user.proto
ln -s $GOPATH/bgs/grpc/pb/service/user_pv_log.proto ./pb/service/user_pv_log.proto
ln -s $GOPATH/bgs/grpc/pb/service/fan.proto ./pb/service/fan.proto


#2、生成grpc gen js
grpc_tools_node_protoc \
-I ./pb \
--js_out=import_style=commonjs,binary:./src/grpc-client/ \
--grpc_out=./src/grpc-client \
--plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` \
shared/message.proto shared/gogo.proto

grpc_tools_node_protoc \
-I ./pb \
--js_out=import_style=commonjs,binary:./src/grpc-client/ \
--grpc_out=./src/grpc-client \
--plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` \
util/status.proto

grpc_tools_node_protoc \
-I ./pb \
--js_out=import_style=commonjs,binary:./src/grpc-client/ \
--grpc_out=./src/grpc-client \
--plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` \
service/user.proto service/user_pv_log.proto service/fan.proto

grpc_tools_node_protoc \
-I ./pb \
--js_out=import_style=commonjs,binary:./src/grpc-client/ \
--grpc_out=./src/grpc-client \
--plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` \
others/account.proto

#3、生成 d.ts codes
protoc \
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
--ts_out=./src/grpc-client/ \
-I ./pb \
shared/message.proto shared/gogo.proto

protoc \
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
--ts_out=./src/grpc-client/ \
-I ./pb \
util/status.proto

protoc \
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
--ts_out=./src/grpc-client/ \
-I ./pb \
service/user.proto service/user_pv_log.proto service/fan.proto

protoc \
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
--ts_out=./src/grpc-client/ \
-I ./pb \
others/account.proto